<template>
  <div class="business">
    <header class="nav">
      <div>
        <span @click="$back()">
          <el-icon color="#fff" size="26">
            <Back />
          </el-icon>
        </span>
        <ul>
          <li v-for="(item, index) in btn" @click="btnindex = index" :class="btnindex == index ? 'active' : ''">
            {{ $t(item) }}
          </li>
        </ul>
      </div>
      <dl ref="tranform">
        <dd v-for="(item, index) in imgbtn" :key="index" @click="item.callback(item, index)">
          <NuxtImg v-if="imgbtnindex != index" :src="item.img" alt="" />
          <NuxtImg v-else :src="item.imghover" alt="" />
          <span :class="imgbtnindex == index ? 'active' : ''">{{
          $t(item.lang)
        }}</span>
        </dd>
      </dl>
    </header>
    <div style="height: 123px"></div>
    <div class="component">
      <component :is="iscomponent" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, shallowRef, markRaw, defineAsyncComponent } from "vue";
import { Back } from '@element-plus/icons-vue'
let process = markRaw(defineAsyncComponent(() => import("./business/components/process.vue")))
let servico = markRaw(defineAsyncComponent(() => import("./business/components/servico.vue")))
let introduce = markRaw(defineAsyncComponent(() => import("./business/components/introduce.vue")))
let vantagens = markRaw(defineAsyncComponent(() => import("./business/components/vantagens.vue")))
let programa = markRaw(defineAsyncComponent(() => import("./business/components/programa.vue")))
let enter = markRaw(defineAsyncComponent(() => import("./business/components/enter.vue")))
let iscomponent = shallowRef(process);
let btnindex = shallowRef<number>(0);
let imgbtnindex = shallowRef<number>(0);
let btn = shallowReactive<string[]>(["language.business.btn1", "language.business.btn2"]);
let imgbtn = reactive<{lang:string,img:string,imghover:string,component:any,callback:Function}[]>([
  {
    lang: "language.business.tab1",
    img: "/img/bn1.png",
    imghover: "/img/bn1l.png",
    component: process,
    callback: (item: any, index: number) => {
      iscomponent.value = item.component;
      imgbtnindex.value = index;
    },
  },
  {
    lang: "language.business.tab2",
    img: "/img/bn2.png",
    imghover: "/img/bn2l.png",
    component: servico,
    callback: (item: any, index: number) => {
      iscomponent.value = item.component;
      imgbtnindex.value = index;
    },
  },
  {
    lang: "language.business.tab3",
    img: "/img/bn3.png",
    imghover: "/img/bn3l.png",
    component: introduce,
    callback: (item: any, index: number) => {
      iscomponent.value = item.component;
      imgbtnindex.value = index;
    },
  },
  {
    lang: "language.business.tab4",
    img: "/img/bn4.png",
    imghover: "/img/bn4l.png",
    component: vantagens,
    callback: (item: any, index: number) => {
      iscomponent.value = item.component;
      imgbtnindex.value = index;
    },
  },
  {
    lang: "language.business.tab5",
    img: "/img/bn5.png",
    imghover: "/img/bn5l.png",
    component: programa,
    callback: (item: any, index: number) => {
      iscomponent.value = item.component;
      imgbtnindex.value = index;
    },
  },
  {
    lang: "language.business.tab6",
    img: "/img/bn6.png",
    imghover: "/img/bn6l.png",
    component: enter,
    callback: (item: any, index: number) => {
      iscomponent.value = item.component;
      imgbtnindex.value = index;
    },
  },
]);
</script>

<style scoped lang="scss">
header {
  @include flex(column, flex-start, flex-start);
  padding: 30px 15px 0;
  background-color: rgb(35, 36, 37);
  position: fixed;
  width: 100%;
  z-index: 9999;
  left: 0;
  top: 0;

  >div {
    width: calc(100vw - 50px);
    overflow-x: auto;
    @include flex(row, flex-start, center);

    span {
      width: 28px;
      height: 28px;
      border: 2px solid #b5bac8;
      display: block;
      border-radius: 16px;
      cursor: pointer;
      @include flex(row, center, center);
    }

    ul {
      flex: 1;
      @include flex(row, flex-start, center);

      li {
        padding: 4px 10px;
        font-size: 16px;
        line-height: 18px;
        color: #0a906c;
        border: 1px solid #0a906c;
        border-radius: 6px;
        cursor: pointer;
      }

      li {
        margin-left: 15px;
      }

      .active {
        background-color: #0a906c;
        color: #fff;
      }
    }
  }

  dl {
    width: 100%;
    @include flex(row, flex-start, center);
    flex-wrap: nowrap;
    position: relative;
    margin: 15px 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 10px;

    /* 定义滚动条整体样式 */
    &::-webkit-scrollbar {

      width: 4px;
      /* 定义滚动条的宽度 */
      height: 4px;
      display: block;
      /* 对于横向滚动条，这里可以不设置或保持和width一致 */
    }

    /* 定义滚动条滑块样式 */
    &::-webkit-scrollbar-thumb {
      background-color: #b5bac8;
      /* 设置滑块的背景色 */
      border-radius: 2px;
      /* 设置滑块的圆角 */
    }

    /* 定义滚动条轨道样式 */
    &::-webkit-scrollbar-track {
      background-color: #424141;
      border-radius: 2px;
      /* 设置轨道的背景色 */
    }

    /* 横向滚动条样式 */
    .horizontal-scrollbar {
      overflow-x: auto;
      /* 需要有足够内容溢出，才会显示滚动条 */
    }

    /* 在需要横向滚动条的容器上应用样式 */
    .horizontal-scrollbar::-webkit-scrollbar {
      height: 4px;
      /* 设置横向滚动条的高度 */
    }

    .horizontal-scrollbar::-webkit-scrollbar-thumb {
      width: 100px;
      /* 设置横向滑块的宽度 */
    }

    .horizontal-scrollbar::-webkit-scrollbar-track {
      background-color: #f0f0f0;
      /* 设置横向轨道的背景色 */
    }

    dd {
      @include flex(row, flex-start, center);
      cursor: pointer;

      img {
        width: 14px;
        margin-right: 5px;
      }

      span {
        white-space: nowrap;
        font-size: 13px;
        color: #b5bac8;
      }

      .active {
        color: #0a906c;
      }
    }

    dd+dd {
      margin-left: 15px;
    }
  }
}

.business {
  width: 100%;
  min-height: 100vh;
  background-color: rgb(26, 26, 26);

  .component {
    width: 100%;
    position: relative;
    left: 0;
    padding: 20px 15px 120px;
  }
}
</style>
